// pages/feedback/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [{
        id: 0,
        value: "体验问题",
        isActive: true
      },
      {
        id: 1,
        value: "商品、商家投诉",
        isActive: false
      }

    ],
    chooseImages: [],
    textVal: ""
  },

  handleChoose(e) {
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (result) => {
        this.setData({
          chooseImages: [...this.data.chooseImages, ...result.tempFilePaths]
        })
      },
      fail: () => {},
      complete: () => {}
    });
  },

  handleTabsItemChange(e) {
    const {
      index
    } = e.detail;
    let {
      tabs
    } = this.data;
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    this.setData({
      tabs
    })
  },

  handleRemoveImg(e) {
    const {
      index
    } = e.currentTarget.dataset;
    console.log(index);
    let {
      chooseImages
    } = this.data;
    chooseImages.splice(index, 1);

    this.setData({
      chooseImages
    })
  },

  handleTextInput(e) {
    this.setData({
      textVal: e.detail.value
    })
  },

  handleForSubmit() {
    const {
      textVal,
      chooseImages
    } = this.data;
    if (!textVal.trim()) {
      wx.showToast({
        title: '输入不合法',
        icon: 'none',
        mask: true,

      });
      return
    }
    chooseImages.forEach((v, i) => {
      var upTask = wx.uploadFile({
        url: 'https://photo.weibo.com/upload/index?prel=p4_1',

        filePath: v,
        name: "file",
        formData: {},
        success: (result) => {
          console.log(result);
        },
        fail: () => {},
        complete: () => {}
      });
    })
  },
})